package LABS.lab6;

/**************************************************************
* Class Recursion
* @author Jeff Thomas - Thomas007
* @vesion 1.0.0
* Date: 03.17.2008
* Copyright 2008, Jeff Thomas
***************************************************************/
public class Recursion
{
	public static void main(String[] args)
	{
		System.out.println(stutter("hello"));
		System.out.println(toNumber("3ac4"));
	}
/**************************************************************
* Stutter
* @param message - String to apply a stutter
* @return - Stuttered string, hello => hheellllo
* Task:	1. If message is only 1 character, stutter it
*			2.	Traverse each character and recursively call stutter
* Side Effects: None
***************************************************************/	
	public static String stutter(String message)
	{
		String result = "";
		if (message.length() == 1)
		{
			result = message + message;
			return result;
		}
		for (int i = 0; i < message.length(); i++)
		{
			result = result + stutter(message.substring(i,i+1));
		}	
		return result;
	}
/**************************************************************
* toNumber
* @param message - String to calculate sum
* @return - Integer of all numbers in a string
* Task:	1. if the character is a number, add it to the sum
*			2. Traverse the message and recursively call toNumber
* Side Effects: None
***************************************************************/	
	public static int toNumber(String message)
	{
		int sum = 0;
		if (message.length() == 1)
		{
			if (Character.isDigit(message.charAt(0)))
			{
				sum = sum + Character.digit(message.charAt(0), 10);
			}
			return sum;
		}
		for (int i = 0; i < message.length(); i++)
		{
			sum = sum + toNumber(message.substring(i,i+1));
		}
		return sum;
	}
}
/**************************************************************
* I, Jeff Thomas, certify that each part of this program was
* written by me, except as noted within the code.
*
*						_________________________
***************************************************************/